# Maintainer: Simon Zeni <simon@bl4ckb0ne.ca>
pkgname=jellyfin
pkgver=10.8.1
pkgrel=0
pkgdesc="The Free Software Media System"
pkgusers="$pkgname"
pkggroups="$pkgname"
install="$pkgname.pre-install"
url="https://jellyfin.org/"
arch="x86_64" # blocked by runtimes
license="GPL-2.0-only"
makedepends="dotnet6-sdk"
depends="aspnetcore6-runtime ffmpeg"
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/jellyfin/jellyfin/archive/refs/tags/v$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd"
builddir="$srcdir/$pkgname-$pkgver"

build() {
	dotnet build --configuration Release Jellyfin.Server
	dotnet publish --configuration Release Jellyfin.Server --output publish

	# Remove unnecessary runtimes, we only need linux-musl-x64
	# TODO arm and arm64 package
	rm -rf publish/runtimes/alpine-arm
	rm -rf publish/runtimes/alpine-arm64
	rm -rf publish/runtimes/alpine-x64 # Dup of linux-musl-x64
	rm -rf publish/runtimes/browser-wasm
	rm -rf publish/runtimes/linux-arm
	rm -rf publish/runtimes/linux-arm64
	rm -rf publish/runtimes/linux-armel
	rm -rf publish/runtimes/linux-mips64
	rm -rf publish/runtimes/linux-musl-arm
	rm -rf publish/runtimes/linux-musl-arm64
	rm -rf publish/runtimes/linux-s390x
	rm -rf publish/runtimes/linux-x64
	rm -rf publish/runtimes/linux-x86
	rm -rf publish/runtimes/maccatalyst-arm64
	rm -rf publish/runtimes/maccatalyst-x64
	rm -rf publish/runtimes/osx*
	rm -rf publish/runtimes/unix
	rm -rf publish/runtimes/win*
}

check() {
	dotnet test
}

package() {
	mkdir -p "$pkgdir"/usr/lib
	cp -dr publish "$pkgdir"/usr/lib/jellyfin

	mkdir -p "$pkgdir"/usr/bin
	ln -s /usr/lib/jellyfin/jellyfin "$pkgdir"/usr/bin/jellyfin

	install -Dm755 "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
8431d15eb83815c796cdd215f4234b2bdd90ce555036999a4bbb514cb754f8a804815a6e4c70ba183447ede033fa24e3567b59c492d499421d621b496fd06f91  jellyfin-10.8.1.tar.gz
364a70a953d921048a249fd370642c1782e434c850334cd55e35bbb10d1bb93482d37faa1c11da5d7acba96a084d9832e5db212b65b0fa9907c7d3afe553aaf9  jellyfin.initd
d35eb07d11d711b8ad35c7726e151a8096609712fee3bfea00c9adeff8e56660e3cde3d9b0b2dc8a847514af4d2b32340e2b29b77facfab4f8921ba15ba671b0  jellyfin.confd
"
